package com.metaaps.eoclipse.api;

import com.metaaps.eoraster.GeoTransform;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;

public class GeoUtils {

  /**
  * Modify the GeometricLayer so the layer coordinate system matches the image coordinate system ("pixel" projection).
  */
 public static GeometricLayer createImageProjectedLayer(GeometricLayer positions, GeoTransform geoTransform, String projection) {
     positions=positions.clone();
     positions.setProjection(null);
     for(Geometry geom:positions.getGeometries()){
         for(Coordinate pos:geom.getCoordinates()){
             double[] temp=geoTransform.getPixelFromGeo(pos.x, pos.y, projection);
             pos.x=temp[0];
             pos.y=temp[1];
         }
     }
     return positions;
 }
 
 /**
  * Modify the GeometricLayer so the layer coordinates system matches the world coordinate system (EPSG projection).
  */
 public static GeometricLayer createWorldProjectedLayer(GeometricLayer positions, GeoTransform geoTransform, String projection) {
     positions=positions.clone();
     positions.setProjection(projection);
     for(Geometry geom:positions.getGeometries()){
         for(Coordinate pos:geom.getCoordinates()){
             double[] temp=geoTransform.getGeoFromPixel(pos.x, pos.y, projection);
             pos.x=temp[0];
             pos.y=temp[1];
         }
     }
     return positions;
 }


}
